home *** CD-ROM | disk | FTP | other *** search
/ Clickx 47 / Clickx 47.iso / assets / software / Miro_Installer.exe / xulrunner / chrome / toolkit.jar / content / global / alerts / alert.js next >
Encoding:
JavaScript  |  2005-09-30  |  4.4 KB  |  129 lines

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3.  *
  4.  * The contents of this file are subject to the Mozilla Public License Version
  5.  * 1.1 (the "License"); you may not use this file except in compliance with
  6.  * the License. You may obtain a copy of the License at
  7.  * http://www.mozilla.org/MPL/
  8.  *
  9.  * Software distributed under the License is distributed on an "AS IS" basis,
  10.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11.  * for the specific language governing rights and limitations under the
  12.  * License.
  13.  *
  14.  * The Original Code is mozilla.org code.
  15.  *
  16.  * The Initial Developer of the Original Code is
  17.  * Netscape Communications Corporation.
  18.  * Portions created by the Initial Developer are Copyright (C) 1998
  19.  * the Initial Developer. All Rights Reserved.
  20.  *
  21.  * Contributor(s):
  22.  *   Scott MacGregor <mscott@netscape.com>
  23.  *   Jens Bannmann <jens.b@web.de>
  24.  *
  25.  * Alternatively, the contents of this file may be used under the terms of
  26.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  27.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  28.  * in which case the provisions of the GPL or the LGPL are applicable instead
  29.  * of those above. If you wish to allow use of your version of this file only
  30.  * under the terms of either the GPL or the LGPL, and not to allow others to
  31.  * use your version of this file under the terms of the MPL, indicate your
  32.  * decision by deleting the provisions above and replace them with the notice
  33.  * and other provisions required by the GPL or the LGPL. If you do not delete
  34.  * the provisions above, a recipient may use your version of this file under
  35.  * the terms of any one of the MPL, the GPL or the LGPL.
  36.  *
  37.  * ***** END LICENSE BLOCK ***** */
  38.  
  39. var gFinalHeight = 50;
  40. var gSlideIncrement = 1;
  41. var gSlideTime = 10;
  42. var gOpenTime = 3000; // total time the alert should stay up once we are done animating.
  43.  
  44. var gAlertListener = null;
  45. var gAlertTextClickable = false;
  46. var gAlertCookie = "";
  47.  
  48. function prefillAlertInfo()
  49. {
  50.   // unwrap all the args....
  51.   // arguments[0] --> the image src url
  52.   // arguments[1] --> the alert title
  53.   // arguments[2] --> the alert text
  54.   // arguments[3] --> is the text clickable? 
  55.   // arguments[4] --> the alert cookie to be passed back to the listener
  56.   // arguments[5] --> an optional callback listener (nsIObserver)
  57.  
  58.   document.getElementById('alertImage').setAttribute('src', window.arguments[0]);
  59.   document.getElementById('alertTitleLabel').setAttribute('value', window.arguments[1]);
  60.   document.getElementById('alertTextLabel').setAttribute('value', window.arguments[2]);
  61.   gAlertTextClickable = window.arguments[3];
  62.   gAlertCookie = window.arguments[4];
  63.  
  64.   if (gAlertTextClickable)
  65.     document.getElementById('alertTextLabel').setAttribute('clickable', true);
  66.   
  67.   // the 5th argument is optional
  68.   gAlertListener = window.arguments[5];
  69. }
  70.  
  71. function onAlertLoad()
  72. {
  73.   // read out our initial settings from prefs.
  74.   try 
  75.   {
  76.     var prefService = Components.classes["@mozilla.org/preferences-service;1"].getService();
  77.     prefService = prefService.QueryInterface(Components.interfaces.nsIPrefService);
  78.     var prefBranch = prefService.getBranch(null);
  79.     gSlideIncrement = prefBranch.getIntPref("alerts.slideIncrement");
  80.     gSlideTime = prefBranch.getIntPref("alerts.slideIncrementTime");
  81.     gOpenTime = prefBranch.getIntPref("alerts.totalOpenTime");
  82.   } catch (ex) {}
  83.  
  84.   sizeToContent();
  85.  
  86.   gFinalHeight = window.outerHeight;
  87.  
  88.   window.outerHeight = 1;
  89.  
  90.   // be sure to offset the alert by 10 pixels from the far right edge of the screen
  91.   window.moveTo( (screen.availLeft + screen.availWidth - window.outerWidth) - 10, screen.availTop + screen.availHeight - window.outerHeight);
  92.  
  93.   setTimeout(animateAlert, gSlideTime);
  94. }
  95.  
  96. function animateAlert()
  97. {
  98.   if (window.outerHeight < gFinalHeight)
  99.   {
  100.     window.screenY -= gSlideIncrement;
  101.     window.outerHeight += gSlideIncrement;
  102.     setTimeout(animateAlert, gSlideTime);
  103.   }
  104.   else
  105.     setTimeout(closeAlert, gOpenTime);  
  106. }
  107.  
  108. function closeAlert()
  109. {
  110.   if (window.outerHeight > 1)
  111.   {
  112.     window.screenY += gSlideIncrement;
  113.     window.outerHeight -= gSlideIncrement;
  114.     setTimeout(closeAlert, gSlideTime);
  115.   }
  116.   else
  117.   {
  118.     if (gAlertListener)
  119.       gAlertListener.observe(null, "alertfinished", gAlertCookie); 
  120.     window.close(); 
  121.   }
  122. }
  123.  
  124. function onAlertClick()
  125. {
  126.   if (gAlertListener && gAlertTextClickable)
  127.     gAlertListener.observe(null, "alertclickcallback", gAlertCookie);
  128. }
  129.